<?php
require_once( '../../libs/smarty.inc' );
require_once( '../../libs/smt_variables.php' );
require_once( '../../libs/Class_DB.php' );
require_once( '../../libs/Class_ERROR.php' );
require_once( '../../libs/login.inc.php' );
require_once( '../../libs/page_other.php' );
require_once( '../../libs/new_smt_variables.php' );

if( !in_array( "N", $_SESSION['ADMIN_LOGIN']['AUTH_CD'] ) ) exit;

if( $_SERVER['REQUEST_METHOD'] == 'GET'){
	
	$forms = $_GET;
	$shop_name = $_GET["shop_name"];
	$size = $_GET["size"];
	$current=1;
	if( isset( $_GET['page'] ) && is_numeric( $_GET['page'] ) ){
		$current = $_GET['page'];
		$st = ($current -1) * PAGE_SIZE;
	}else{
		$current = 1;
		$st = 0;
	}
	
	$where = '';
	$query = '';
	
	if($shop_name != null){
		$where = $where." and shop_name like '%".$shop_name."%'";
		$query .="&shop_name=".$shop_name;
	}
	if($size != null){
		$where = $where." and size like '%".$size."%'";
		$query .="&size=".$size;
	}
	
	$sql =  "SELECT * FROM k_shop WHERE 1 = 1 $where order by shop_id asc LIMIT $st, ".PAGE_SIZE;
	$sqlcount ="SELECT COUNT(*) as cnt FROM k_shop WHERE 1=1 ".$where;
	$db = new Class_DB;
	$res = $db->query($sql);
	
	while( $row = mysql_fetch_array($res,MYSQL_ASSOC) ){
		$shoplist[] = $row;
	}
	
	$cnt = 0;
	$db->query( $sqlcount );
	$row = $db->fetch();
	$cnt = $row['cnt'];
	
	$smarty->assign('page', getPage($current, $cnt,$query));
	if( isset( $forms ) ) $smarty->assign('forms', $forms);
	
	/******/
}

$menu_html = file_get_contents( $_SERVER['DOCUMENT_ROOT'].'/templates/web-admin/menu.html' );

$smarty->assign('menu_html', $menu_html);

$smarty->assign('shoplist', $shoplist);

$smarty->assign('cnt', $cnt);

$smarty->display('web-admin/order_shop_search.html');


?>